package com.crm.system.service.impl.user;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.EducationalExperience;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.UserInfo;
import com.crm.model.entity.sys.UserInfoSubordinate;
import com.crm.model.vo.user.UserInfoVO;
import com.crm.service.sys.UserEducationalExperienceDbService;
import com.crm.service.sys.UserInfoDbService;
import com.crm.service.sys.UserInfoSubordinateDbService;
import com.crm.system.service.user.UserEducationalExperienceService;
import com.crm.system.service.user.UserInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 教育经历
 * @author baijian
 * @date 2021/3/22 11:23
 */
@Service
public class UserEducationalExperienceServiceImpl implements UserEducationalExperienceService {

    @Autowired
    private UserEducationalExperienceDbService userEducationalExperienceDbService;

    /**
     * 根据用户id查询教育经历
     * @param userId 用户id
     * @return
     */
    @Override
    public List<EducationalExperience> educationalExperienceList(String userId) {
        return userEducationalExperienceDbService.educationalExperienceList(userId);
    }

    /**
     * 个人信息-新增教育经历
     * @param educationalExperience 教育经历实体
     * @return
     */
    @Override
    public Boolean addAndEditEducationalExperience(EducationalExperience educationalExperience) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        Boolean result = false;
        if(StringUtils.isBlank(educationalExperience.getEducationalExperienceId())){
            String educationalExperienceId = CommonUtils.getGUID();
            educationalExperience.setEducationalExperienceId(educationalExperienceId);
            educationalExperience.setCreateId(userAccount.getAccountId());
            educationalExperience.setCreateTm(new Date());
            educationalExperience.setUpdateUserId(userAccount.getAccountId());
            educationalExperience.setUpdateTm(new Date());
            result = userEducationalExperienceDbService.addEducationalExperience(educationalExperience);
        }else{
            educationalExperience.setUpdateUserId(userAccount.getAccountId());
            educationalExperience.setUpdateTm(new Date());
            result = userEducationalExperienceDbService.updateEducationalExperience(educationalExperience);
        }

        return result;
    }

    /**
     * 个人信息-修改教育经历回显
     * @param educationalExperienceId 常用语id
     * @return
     */
    @Override
    public EducationalExperience getEducationalExperienceById(String educationalExperienceId) {
        return userEducationalExperienceDbService.getEducationalExperienceById(educationalExperienceId);
    }

    /**
     * 个人信息-修改教育经历
     * @param educationalExperience 教育经历实体
     * @return
     */
    @Override
    public Boolean updateEducationalExperience(EducationalExperience educationalExperience) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        educationalExperience.setUpdateUserId(userAccount.getAccountId());
        educationalExperience.setUpdateTm(new Date());
        Boolean result = userEducationalExperienceDbService.updateEducationalExperience(educationalExperience);
        return result;
    }
}
